package org.msfj.admin.data.controller;

import org.msfj.admin.model.Metadata;
import org.msfj.admin.vo.MetadataVo;
import org.msfj.admin.model.Metadata;
import org.msfj.admin.vo.MetadataVo;
import org.msfj.admin.model.Metadata;
import org.msfj.admin.vo.MetadataVo;
import org.msfj.admin.data.service.MetadataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CommonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 系统元数据controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2017-08-10 17:30:21
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "系统元数据接口", tags = "系统元数据接口")
@RestController
@RequestMapping("data/metadata")
public class MetadataController extends BaseController{

    @Autowired
    private MetadataService metadataService;

    /**
     * 添加系统元数据
     *
     * @param metadataVo
     * @return CommonResult.ok(MetadataVo)
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加系统元数据",notes = "添加系统元数据")
    @ApiImplicitParam(value = "metadataVo",name = "metadataVo",dataType = "org.msfj.admin.vo.MetadataVo",paramType = "query")
    public CommonResult addMetadata(MetadataVo metadataVo){
        Metadata metadata = metadataService.saveOrEdit(metadataVo);
        return CommonResult.ok(metadataService.setOtherProperties(metadata));
    }

    /**
     * 修改系统元数据
     *
     * @param metadataVo
     * @return CommonResult.ok(MetadataVo)
     */
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改系统元数据",notes = "修改系统元数据")
    @ApiImplicitParam(value = "metadataVo",name = "metadataVo",dataType = "org.msfj.admin.vo.MetadataVo",paramType = "query")
    public CommonResult editMetadata(MetadataVo metadataVo){
        Metadata metadata = metadataService.saveOrEdit(metadataVo);
        return CommonResult.ok(metadataService.setOtherProperties(metadata));
    }

    /**
     * 逻辑删除系统元数据
     *
     * @param metadataVo
     * @return CommonResult.ok(MetadataVo)
     */
    @PostMapping("/del")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统元数据",notes = "逻辑删除系统元数据")
    @ApiImplicitParam(value = "metadataVo",name = "metadataVo",dataType = "org.msfj.admin.vo.MetadataVo",paramType = "query")
    public CommonResult delMetadata(MetadataVo metadataVo){
        Metadata metadata = metadataService.delById(metadataVo);
        return CommonResult.ok(metadataService.setOtherProperties(metadata));
    }

    /**
     * 逻辑删除系统用户信息
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统元数据",notes = "逻辑删除系统元数据")
    @ApiImplicitParam(value = "ids",name = "ids",dataType = "java.util.List",paramType = "query")
    public CommonResult delUsers(@RequestParam(value = "ids[]",required = false) List<String> ids){
        Metadata metadata = new Metadata();
        metadataService.delByIds(ids, metadata);
        return CommonResult.ok();
    }

    /**
     * 真实删除系统元数据
     *
     * @param metadataVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "真实删除系统元数据",notes = "真实删除系统元数据")
    @ApiImplicitParam(value = "metadataVo",name = "metadataVo",dataType = "org.msfj.admin.vo.MetadataVo",paramType = "query")
    public CommonResult deleteMetadata(MetadataVo metadataVo){
        metadataService.trueDelById(metadataVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找系统元数据
     *
     * @param metadataVo
     * @return CommonResult.ok(MetadataVo)
     */
    @GetMapping("/get")
    @ResponseBody
    @ApiOperation(value = "根据id查找系统元数据",notes = "根据id查找系统元数据")
    @ApiImplicitParam(value = "metadataVo",name = "metadataVo",dataType = "org.msfj.admin.vo.MetadataVo",paramType = "query")
    public CommonResult getMetadata(MetadataVo metadataVo){
        Metadata metadata = metadataService.getById(metadataVo.getId());
        return CommonResult.ok(metadataService.setOtherProperties(metadata));
    }

    /**
     * 根据翻页参数、搜索参数查找系统元数据
     *
     * @param metadataVo
     * @param page 当前第几页
     * @param rows 每页多少条记录
     * @return CommonResult.ok(PageInfo<MetadataVo>)
     */
    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "根据翻页参数、搜索参数查找系统元数据",notes = "根据翻页参数、搜索参数查找系统元数据")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "metadataVo",name = "metadataVo",dataType = "org.msfj.admin.vo.MetadataVo",paramType = "query"),
        @ApiImplicitParam(name = "page",value = "page",dataType = "Integer",paramType = "path"),
        @ApiImplicitParam(name = "rows",value = "rows",dataType = "Integer",paramType = "path")
    })
    public CommonResult findMetadataList(MetadataVo metadataVo, Integer page, Integer rows){
        PageInfo<MetadataVo> metadataVoPageInfo = metadataService.getByMetadata(metadataVo,page,rows);
        return CommonResult.ok(metadataVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有系统元数据
     *
     * @param metadataVo
     * @return CommonResult.ok(List<MetadataVo>)
     */
    @GetMapping("/getAll")
    @ResponseBody
    @ApiOperation(value = "根据搜索参数查找所有系统元数据",notes = "根据搜索参数查找所有系统元数据")
    @ApiImplicitParam(value = "metadataVo",name = "metadataVo",dataType = "org.msfj.admin.vo.MetadataVo",paramType = "query")
    public CommonResult getAllMetadata(MetadataVo metadataVo){
        List<MetadataVo> metadataVoList = metadataService.getAllMetadata(metadataVo);
        return CommonResult.ok(metadataVoList);
    }
}
